import Axios, { AxiosRequestConfig } from "axios";
import { BackendResponse } from "@/ui/utils/backend/meta";

const BACKEND_HOST = process.env.BACKEND_HOST;

export const axios = Axios.create({
  baseURL: `${BACKEND_HOST}/api`,
  withCredentials: true,
});

export function request<R = unknown>(
  url: string,
  data?: any,
  config?: AxiosRequestConfig,
) {
  return axios.request<BackendResponse<R>>({
    url,
    data,
    method: "post",
    ...config,
  });
}
